package com.mxf.code.controller;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.mxf.code.UserRequest;
import com.mxf.code.enums.SexEnum;
import com.mxf.code.mapper.UserMapper;
import com.mxf.code.pojo.User;
import com.mxf.code.request.EditRequest;
import com.mxf.code.request.InsertRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author mxf
 * @version 1.0
 * @description: TODO
 * @date 2023/1/11
 */
@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserMapper userMapper;

    @GetMapping("sex/1")
    public SexEnum getSex1(UserRequest userRequest) {
        return userRequest.getSex();
    }

    @GetMapping("sex/2")
    public SexEnum getSex2(SexEnum sex) {
        return sex;
    }

    @PostMapping("sex/add/1")
    public SexEnum insertSex1(SexEnum sex) {
        User user = new User();
        Snowflake snowflake = IdUtil.createSnowflake(1L, 1L);
        user.setId(snowflake.nextId());
        user.setName("2023测试");
        user.setAge(12);
        user.setEmail("123@qq.com");
        user.setSex(sex);
        user.setIsDeleted(0);
        int insert = userMapper.insert(user);
        System.out.println(insert);
        System.out.println(user.getId());
        return sex;
    }

    @PostMapping("sex/add/2")
    public SexEnum insertSex2(@RequestBody InsertRequest request) {
        return request.getSex();
    }

    @PutMapping("sex/edit/1")
    public SexEnum editSex1(SexEnum sex) {
        return sex;
    }

    @PutMapping("sex/edit/2")
    public SexEnum editSex2(@RequestBody EditRequest request) {
        return request.getSex();
    }
}
